function getContext() {
    $.ajax({
        method: "get",
        url: "http://www.liulongbin.top:3006/api/cmtlist",
        success: function (res) {
            console.log(res)
            if (res.status != 200) {
                return alert('获取评论失败')
            } else {
                var data = [];
                $.each(res.data, function (i,item) {
                    data.push('<li class="list-group-item">'+item.content+
                    '<span class="badge" style="background-color:#ffd867;">'+item.time+'</span>'+
                    '<span class="badge" style="background-color:#007acc;">'+item.username+'</span>'+
               '</li>')
                })
                $('#mycontents').empty().append(data.join(''));
            }
        }
    });
}
getContext();

$(function () {
    $('#addContent').submit(function (e) {
        e.preventDefault();
        var data = $(this).serialize();
        console.log(data);
        $.post('http://www.liulongbin.top:3006/api/addcmt', data, function (res) {
            if (res.status != 201) {
                return alert('发表评论失败')
            }

                getContext();
                $('#addContent')[0].reset();
            
        })
    });
 })